package com.jojo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/user")
public class LoginController {
   /* @RequestMapping("/login")
    public String login(HttpSession session, String username, String password) {
        System.out.println("login==>"+username);

        //把用户信息存在session中
        session.setAttribute("userLoginInfo", username);
        return "main";
    }*/

    @RequestMapping("/login")
    public String login(HttpServletRequest request, String username, String password,Model model) {
        System.out.println("login==>"+username);
        username=request.getParameter("username");

        //把用户信息存在session中
        request.getSession().setAttribute("userLoginInfo", username);
        model.addAttribute("username",username);
        return "main";
    }

    @RequestMapping("/loginOut")
    public String loginOut(HttpServletRequest request) {

        //把用户信息存在session中
        request.getSession().removeAttribute("userLoginInfo");

        return "redirect:/user/main";
    }

    @RequestMapping("/main")
    public String main(){
        return "main";
    }
    @RequestMapping("/goLogin")
    public String login(){
        return "login";
    }
}
